package Basics;

import vecmath.Tuple3d;
//import vecmath;

public class myVector extends Tuple3d{

	public myVector () {	
		super();
	}
	
	public myVector(double[] arrayOfCoordinates) {
		super(arrayOfCoordinates);
	}
	
	public myVector (double x, double y, double z) {
		super(x,y,z);
	}
	
	public myVector (myVector v) {
		super(v);
	}
	
	 public myVector(my3DPoint p1, my3DPoint p2) {
	        super(p2.getX() - p1.getX(), p2.getY() - p1.getY(), p2.getZ() - p1.getZ());
	    }
	
	
	public myVector addToVector(Tuple3d pointOrVector) {
		
		this.x = this.x+ pointOrVector.getX();
		this.y = this.y+ pointOrVector.getY();
		this.z = this.z+pointOrVector.getZ();
		return this;
	}
	
	public myVector substractFromVector(Tuple3d pointOrVector) {
		Tuple3d t = new myVector(-pointOrVector.getX(),-pointOrVector.getY(), -pointOrVector.getZ()); 
		return addToVector(t);
	}
	
	
	
	public myVector ScaleVector(double ScaleFactor) {
		this.x = this.x*ScaleFactor;
		this.y = this.y*ScaleFactor;
		this.z = this.z*ScaleFactor;
		return this;
	}
	
	public double standardEuclidianNorm() {		
		return Math.sqrt(Math.pow(this.getX(), 2) + Math.pow(this.getY(), 2) + Math.pow(this.getZ(), 2));
	}
	
	public myVector normalize() {
		
		this.x = this.x/this.standardEuclidianNorm();
		this.y = this.y/this.standardEuclidianNorm();
		this.z = this.z/this.standardEuclidianNorm();
		return this;
		
	}
	
	//returns the dot product with this vector and another vector
	public double dotProduct(myVector v) {
		return (this.x*v.getX() + this.y*v.getY() + this.z*v.getZ());
		
	}
	
	//returns the dot product with this vector and another vector
	public myVector crossProduct(myVector v) {
		return new myVector(this.y*v.getZ()-this.z*v.getY(), this.z*v.getX()-this.x*v.getZ(), this.x*v.getY()-this.y*v.getX());			
	}
	
	public boolean isCollinearTo (myVector v){
		double firstCompFactor = v.getX()/this.getX();
		if ((v.getY()/this.getY() == firstCompFactor) && (v.getZ()/this.getZ() == firstCompFactor)) return true;
		else return false;
		
	}
	
	
	
	
}
